///////////////////////////////////////////////////////////////////////////
//
// Spring Engine Source File.
// Copyright (C), Dengtao 2011-2021
// ----------------------------------------------------------------------
// File name:   SfMemoryAllocManager.inl
// Version:     v1.0.0
// Created:     2013/06/13 23:55 by dengtao
// Compilers:   Visual Studio 2008
// Description: 
// ----------------------------------------------------------------------
// History:
//
///////////////////////////////////////////////////////////////////////////

//
//Summary:
//	set allocator.
inline void MemoryAllocManager::SetAllocator(MemoryAllocator* allocator)
{
	m_Allocator = allocator;
}

inline MemoryAllocator* MemoryAllocManager::GetAllocator()
{
	return m_Allocator;
}

inline const MemoryAllocator* MemoryAllocManager::GetAllocator() const
{
	return m_Allocator;
}

//
//Summary:
//	memory tracker
inline void MemoryAllocManager::SetTracker(MemoryTracker* trakcer)
{
	m_Tracker = trakcer;
}

inline MemoryTracker* MemoryAllocManager::GetTracker()
{
	return m_Tracker;
}

inline const MemoryTracker* MemoryAllocManager::GetTracker() const
{
	return m_Tracker;
}

//
//Summary:
//    MemAlloc 
inline void* MemoryAllocManager::MemAlloc(size_t size)
{
	SfAssert(size > 0);

	if (SfNull != m_Allocator)
	{
		return m_Allocator->Alloc(size);
	}

	// use c-style malloc
	return m_DefaultAllocator.Alloc(size);
}

//
//Summary:
//	MemFree
inline bool MemoryAllocManager::MemFree(void* p)
{
	SfAssertValidPtr(p);

	if (SfIsValidPtr(m_Allocator))
	{
		return m_Allocator->Free(p);
	}

	// use c-style free
	return m_DefaultAllocator.Free(p);
}

//
//Summary:
//	raise event_MemroyWarning.
inline void MemoryAllocManager::RaiseMemoryWarning(size_t requestSize)
{
	evnet_MemoryWarning(this, requestSize);
}
